﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Xml.Serialization;
using System.IO;

using System.Net;


namespace PerformanceMetrics
{
    public class Performance
    {
        private DateTime _dtStart;
        private DateTime _dtEnd;
        private string _methodName = "";
        private string _className, _assemblyName, _version;
        private long _objectSize = 0;
        private double _totalRuntime = 0.0f;
        public void StartTimer() { }

        public Performance(string assemblyName, string className, string methodName, string version)
        {
            if (methodName != null)
                _methodName = methodName;
            _assemblyName = assemblyName;
            _className = className;
            _version = version;

            this._dtStart = DateTime.Now;

        }
        public void StartTest()
        {
            _dtStart = DateTime.Now;

        }

        public void EndTest()
        {
            _totalRuntime = DateTime.Now.Subtract(_dtStart).TotalMilliseconds / 1000;
            Debug.WriteLine(String.Format("Test run {0} Took {1} seconds.", _methodName, _totalRuntime));
         


        }
        public int ReportObjectSize<T>(T obj, string messagePrePend) where T : IXmlSerializable
        {

            XmlSerializer xs = new XmlSerializer(typeof(T));

            MemoryStream ms = new MemoryStream();
            xs.Serialize(ms, obj);
            _objectSize = ms.Length;
            Debug.WriteLine(string.Format("Total result object size {0} bytes", _objectSize));
            return (int)_objectSize;

        }


    }
}
